package main.scala.chapter02

import scala.collection.mutable
import scala.util.Random

object Test35_PlayCard {
  def main(args: Array[String]): Unit = {
    //做一套扑克牌
    val numbers = List("A", "2", "3", "4", "5", "6",
      "7", "8", "9", "10", "J", "Q", "K")
    val flowers = List("♠", "♥", "♣", "♦")
    val buffer = mutable.ListBuffer[String]()
    for(i<-numbers;j<-flowers) buffer.append(j+i)
    println(buffer)
    val list = for (i <- numbers; j <- flowers) yield j + i
    println(list)
    //使用算子的方式生成
    val list1 = numbers.flatMap(e => {
      flowers.map(f => f + e)
    })
    println(list1)
    //加入大王小王
    val list2 = list1 :+ "大王" :+ "小王"
    println(list2)
    //洗牌
    val list3 = Random.shuffle(list2)
    println(list3)
    //发牌
    val dipai = list3.take(3)
    val list4 = list3.drop(3)
    //分别发给3个玩家
    val player1 = list4.take(17)
    val player2 = list4.slice(17, 34)
    val player3 = list4.takeRight(17)
    println(player1)
    println(player2)
    println(player3)
    println(dipai)
    println(player1.sortWith((x,y)=>{
      x.substring(1)<y.substring(1)
    }))
  }
}
